package atshool.ruanjian.erban.Controller;


import atshool.ruanjian.erban.Entity.Ajax;
import atshool.ruanjian.erban.Entity.Page;
import atshool.ruanjian.erban.Entity.test;
import atshool.ruanjian.erban.Service.testService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping(value = "/test")
public class testController {

    @Autowired
    private testService testService;

    /**
     * 保存方法
     * @param test
     * @return
     */
    @GetMapping("/save")
    public Ajax save (test test) {
        testService.save(test);
      return Ajax.success();
    }

    @GetMapping("/list")
    public Ajax list(test test, HttpServletRequest request, HttpServletResponse response) {
        String no = request.getParameter("pageNo");
        Page<test> page = testService.findPage(test,no);
        return Ajax.success().put("page",page);
    }
    @DeleteMapping("delete")
    public Ajax delete(String ids) {
        String idArray[] =ids.split(",");
        for(String id : idArray){
            testService.delete(id);
        }
        return Ajax.success("删除");
    }
}
